package com.hqyj.javaSpringBoot.modules.test.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.hqyj.javaSpringBoot.modules.common.entity.SearchBean;
import com.hqyj.javaSpringBoot.modules.test.entity.City;
import com.hqyj.javaSpringBoot.modules.test.entity.Country;
import com.hqyj.javaSpringBoot.modules.test.service.CountryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class CountryController {

    @Autowired
    private CountryService countryService;

    /**
     * 127.0.0.1/api/country/522 ---- get
     */
    // @PathVariable 接收请求路径中占位符的值
    @GetMapping("/country/{countryId}")
    public Country getCountryByCountryId(@PathVariable int countryId) {
        return countryService.getCountryByCountryId(countryId);
    }

    /**
     * 127.0.0.1/api/country?countryName=China&localCountryName=Zhongquo ---- get
     */
    //@RequestParam(required = false)
    //@RequestParam：将url中的参数绑定到方法参数 可设置参数值
    //required:是否包含该参数，默认为true，表示该请求路径中必须包含该参数，如果不包含就报错。
    @GetMapping("/country")
    public Country getCountryByCountryName(@RequestParam String countryName,
                                           @RequestParam String localCountryName) {
        return countryService.getCountryByCountryName(countryName, localCountryName);
    }

}
